package com.ruoyi.cms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cms.domain.CmsSiteBanner;
import com.ruoyi.cms.service.ICmsSiteBannerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 模块轮播内容信息Controller
 * 
 * @author ruoyi
 * @date 2022-08-29
 */
@RestController
@RequestMapping("/cms/banner")
public class CmsSiteBannerController extends BaseController
{
    @Autowired
    private ICmsSiteBannerService cmsSiteBannerService;

    /**
     * 查询模块轮播内容信息列表
     */
    @PreAuthorize("@ss.hasPermi('cms:banner:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmsSiteBanner cmsSiteBanner)
    {
        startPage();
        List<CmsSiteBanner> list = cmsSiteBannerService.selectCmsSiteBannerList(cmsSiteBanner);
        return getDataTable(list);
    }

    /**
     * 导出模块轮播内容信息列表
     */
    @PreAuthorize("@ss.hasPermi('cms:banner:export')")
    @Log(title = "模块轮播内容信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmsSiteBanner cmsSiteBanner)
    {
        List<CmsSiteBanner> list = cmsSiteBannerService.selectCmsSiteBannerList(cmsSiteBanner);
        ExcelUtil<CmsSiteBanner> util = new ExcelUtil<CmsSiteBanner>(CmsSiteBanner.class);
        util.exportExcel(response, list, "模块轮播内容信息数据");
    }

    /**
     * 获取模块轮播内容信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:banner:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(cmsSiteBannerService.selectCmsSiteBannerById(id));
    }

    /**
     * 新增模块轮播内容信息
     */
    @PreAuthorize("@ss.hasPermi('cms:banner:add')")
    @Log(title = "模块轮播内容信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsSiteBanner cmsSiteBanner)
    {
        return toAjax(cmsSiteBannerService.insertCmsSiteBanner(cmsSiteBanner));
    }

    /**
     * 修改模块轮播内容信息
     */
    @PreAuthorize("@ss.hasPermi('cms:banner:edit')")
    @Log(title = "模块轮播内容信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsSiteBanner cmsSiteBanner)
    {
        return toAjax(cmsSiteBannerService.updateCmsSiteBanner(cmsSiteBanner));
    }

    /**
     * 删除模块轮播内容信息
     */
    @PreAuthorize("@ss.hasPermi('cms:banner:remove')")
    @Log(title = "模块轮播内容信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmsSiteBannerService.deleteCmsSiteBannerByIds(ids));
    }
}
